﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using Entity.Car_Rental;

namespace Data.Car_Rental
{
    public class OrderItemRespository : Car_RentalRepositoryBase, IOrderItemRespository
    {

        #region IRepository<OrderItem> 成员

        public void Update(Entity.Car_Rental.OrderItem entity)
        {
            base.UpdateEntity(entity);
        }

        public void Update(IList<Entity.Car_Rental.OrderItem> list)
        {
            base.UpdateEntity(list.Cast<EntityBase>().ToList());
        }

        public void Insert(Entity.Car_Rental.OrderItem entity)
        {
            base.InsertEntity(entity);
        }

        public void Insert(IList<Entity.Car_Rental.OrderItem> list)
        {
            base.InsertEntity(list.Cast<EntityBase>().ToList());

        }

        public Entity.Car_Rental.OrderItem InsertGetIDENTITY(Entity.Car_Rental.OrderItem entity)
        {
            base.InsertEntity(entity);
            return this.Find(entity.PrimaryKey);
        }

        public void Delete(Entity.Car_Rental.OrderItem entity)
        {
            base.DeleteEntity(entity);
        }

        public void Delete(IList<Entity.Car_Rental.OrderItem> list)
        {
            base.DeleteEntity(list.Cast<EntityBase>().ToList());
        }

        public IQueryable<Entity.Car_Rental.OrderItem> GetModel()
        {
            return base.GetEntities<OrderItem>().Select(i => new OrderItem_Ext
            {
                OrderID = i.OrderID,
                OrderItemID = i.OrderItemID,
                ProductID = i.ProductID,
                ProductName = i.ProductName,
                Quantity = i.Quantity,
                SalePrice = i.SalePrice,
                Status = i.Status,
            });
        }

        public Entity.Car_Rental.OrderItem Find(params object[] keyValues)
        {
            return base.Find<OrderItem>(keyValues);
        }

        #endregion

        #region IOrderItemRespository 成员

        public IQueryable<OrderItem> GetDetailModel()
        {
            var linq = from i in base.GetEntities<OrderItem>()
                       join j in new RentalRecordRepository().GetModel() on i.OrderItemID equals j.OrderItemID
                       select new OrderItem_Ext
                        {
                            OrderID = i.OrderID,
                            OrderItemID = i.OrderItemID,
                            ProductID = i.ProductID,
                            ProductName = i.ProductName,
                            Quantity = i.Quantity,
                            SalePrice = i.SalePrice,
                            Status = i.Status,
                            RentalRecord_Extend = j,
                        };
            return linq;
        }

        #endregion
    }
}
